/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package businesslogic;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author cloud
 */
public class AccessDBManager {
    
    public String accessDB()
    {
        String url = "jdbc:derby://localhost:1527/sample";
        String user = "app";
        String pwd = "app";
        String result = "";
        try
        {
            DriverManager.registerDriver(new org.apache.derby.jdbc.ClientDriver());
            Connection c = DriverManager.getConnection(url, user, pwd) ;
            Statement st = c.createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM CUSTOMER");
            
            while (rs.next())
            {
             System.out.println("NAME = " + rs.getString("NAME")
                     + ", CITY = " + rs.getString("CITY")); 
             result += "NAME = " + rs.getString("NAME")
                     + ", CITY = " + rs.getString("CITY") + "<br />";
            }
            rs.close();
            st.close();
            c.close();
        }
        catch (SQLException e)
        {
            System.out.println(e.getMessage());
        }
        return result;
    }
    public static void main(String[] args)
    {
        AccessDBManager obj = new AccessDBManager();
        obj.accessDB();
    }
    
}
